package com.termine.bean;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import com.termine.dao.AppointmentDAO;
import com.termine.dao.AvailabilityDAO;
import com.termine.dao.LocationDAO;
import com.termine.dao.PersonalDataDAO;
import com.termine.dao.ServiceDAO;
import com.termine.jsf.ClientScheduleJSF;
import com.termine.jsf.LoginJSF;
import com.termine.logic.AppointmentManager;
import com.termine.logic.PersonalDataManager;

public class Bean {
	
	public void setInfoMessage(String message) {
		FacesContext context = FacesContext.getCurrentInstance();
		context.getExternalContext().getFlash().setKeepMessages(true);
		context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"INFO", message));
	}
	
	public void setErrorMessage(String message) {
		FacesContext context = FacesContext.getCurrentInstance();
		context.getExternalContext().getFlash().setKeepMessages(true);
		context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"ERROR", message));
	}
	
	public void setFatalMesssage(String message) {
		FacesContext context = FacesContext.getCurrentInstance();
		context.getExternalContext().getFlash().setKeepMessages(true);
		context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"FATAL ERROR", message));
	}
	
	/*
	 * Bean Getters
	 */
	public ClientScheduleJSF getClientScheduleJSF() {
		return (ClientScheduleJSF) getBean("clientScheduleJSF");
	}
	
	public LoginJSF getLoginJSF() {
		return (LoginJSF) getBean("loginJSF");
	}
	
	public PersonalDataManager getPersonalDataManager() {
		return (PersonalDataManager) getBean("personalDataManager");
	}
	
	public AppointmentManager getAppointmentManager() {
		return (AppointmentManager) getBean("appointmentManager");
	}
	
	public AppointmentDAO getAppointmentDAO() {
		return (AppointmentDAO) getBean("appointmentDAO");
	}
	
	public AvailabilityDAO getAvailabilityDAO() {
		return (AvailabilityDAO) getBean("availabilityDAO");
	}
	
	public ServiceDAO getServiceDAO() {
		return (ServiceDAO) getBean("serviceDAO");
	}
	
	public LocationDAO getLocationDAO() {
		return (LocationDAO) getBean("locationDAO");
	}

	public PersonalDataDAO getPersonalDataDAO() {
		return (PersonalDataDAO) getBean("personalDataDAO");
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T getBean(String beanName) {
	    FacesContext context = FacesContext.getCurrentInstance();
	    return (T) context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);
	}
}
